PATHMac OS 8 and 9 Developer Documentation > Interapplication Communication > AppleScript for Scripters >

AppleScript Language Guide

   

Using the Predefined Result Variable

In addition to displaying the result of a command in the result window, AppleScript puts the result into a predefined variable called result . The value remains there until the next command is executed. If the next command does not return a result, the value of result is undefined. The following two commands show how to use the result variable to set the value of numFiles to the value returned by the Count command:

tell application "Finder"
    count files in folder "Apple Extras" of startup disk
    set numFiles to result
end tell

When a direct parameter specifies more than one object, the result is a list that contains a value for each object that was handled. Here is an example of a command whose result is a list:

tell application "Finder"
    get name of every file in folder "Apple Extras" of startup disk
end tell

The result is a list of strings, one for each file (not including folders or files enclosed in folders). Depending on the contents of the Apple Extras folder, the list looks something like the following:

{"Key Caps", "Language Register", "Register with Apple"}

The first string is the name of the first file, the second string is the name of the second file, and so on.


© 1999 Apple Computer, Inc. – (Last Updated 21 May 99)